namespace UnorderedMap
{
	template<class K, class V, class Hash = HashFun<K>>
	class unordered_map
	{
		struct KeyMap
		{
			const K& operator()(const pair<K, V>& key)
			{
				return key.first;
			}
		};
	public:
		typedef typename HashBucket::_HashTable<K, pair<K, V>, Hash, KeyMap>::iterator iterator;
		iterator begin() { return _hash.begin(); }
		iterator end() { return _hash.end(); }

		pair<iterator, bool> insert(const pair<K, V>& kv) { return _hash.insert(kv); }
		iterator find(const K& k) { return _hash.find(k); }
		bool erase(const K& k) { return _hash.erase(k); }

		V& operator[](const K& k)
		{
			pair<iterator, bool> ret = insert(make_pair(k, V()));
			return ret.first->second;
		}

	private:
		HashBucket::_HashTable<K, pair<K, V>, Hash, KeyMap> _hash;
	};

	void test_map()
	{
		unordered_map<string, string> dict;
		dict.insert(make_pair("sort", "排序"));
		dict.insert(make_pair("string", "字符串"));
		dict.insert(make_pair("left", "左边"));

		unordered_map<string, string>::iterator it = dict.begin();
		while (it != dict.end())
		{
			cout << it->first << ":" << it->second << endl;
			++it;
		}
		cout << endl;

		unordered_map<string, int> countMap;
		string arr[] = { "苹果", "苹果", "香蕉", "西瓜", "苹果", "香蕉", "西瓜", "苹果", "梨子", "香蕉", "西瓜" };
		for (auto e : arr)
		{
			countMap[e]++;
		}

		for (auto& kv : countMap)
		{
			cout << kv.first << ":" << kv.second << endl;
		}
	}
}
